package main

import (
	"encoding/json"

	"jlpay-sdk-go/pkg/jlpay/demo"
	"jlpay-sdk-go/pkg/jlpay/models"
	"jlpay-sdk-go/pkg/jlpay/services"
	"jlpay-sdk-go/pkg/jlpay/utils"
)

// 提现申请示例
func withdrawApplyDemo(clearingService *services.ClearingService) {
	// 创建提现申请请求
	request := models.NewWithdrawApplyRequest()

	// 直接使用map构建请求
	requestMap := map[string]interface{}{
		"org_no":        "123456",
		"merch_no":      "849584358120018", // T0结算商户
		"amount":        "10",
		"settle_type":   "T0",
		"out_settle_id": "1234567890128",
		"notify_url":    "https://www.baidu.com",
		"postscript":    "附言",
	}

	// 设置原始请求数据
	request.SetRawRequestMap(requestMap)

	// 序列化请求数据并打印
	requestJSON, _ := json.Marshal(requestMap)
	utils.Debugf("提现申请请求数据: %s", string(requestJSON))

	// 发送请求
	response, err := clearingService.ApplyWithdraw(request)
	if err != nil {
		utils.Errorf("提现申请请求失败: %v", err)
		return
	}

	// 处理响应 - 使用BaseResponse接口的HandleResponse方法
	response.HandleResponse("提现申请")
}

func main() {
	// 设置日志级别为info，显示详细的调试信息
	utils.SetLogLevel("info")

	utils.Info("=============================")
	utils.Info("===== 提现申请示例 开始 =====")
	utils.Info("=============================")

	// 创建配置对象和清算服务
	config := demo.CreateDemoConfig()
	clearingService := services.NewClearingService(config)

	withdrawApplyDemo(clearingService)

	utils.Info("=============================")
	utils.Info("===== 提现申请示例执行完毕 =====")
	utils.Info("=============================")
}
